package mssql

import (
	"database/sql"
	"fmt"
	_ "github.com/denisenkom/go-mssqldb" // 导入MSSQL驱动
)

type MSSQL struct {
	db *sql.DB
}

func NewMSSQLClient(server, user, password, database string) (*MSSQL, error) {
	connString := fmt.Sprintf("server=%s;user id=%s;password=%s;database=%s", server, user, password, database)
	db, err := sql.Open("mssql", connString)
	if err != nil {
		return nil, err
	}

	return &MSSQL{
		db: db,
	}, nil
}

func (m *MSSQL) Query(query string, args ...interface{}) (*sql.Rows, error) {
	return m.db.Query(query, args...)
}
func (m *MSSQL) QueryRow(query string, args ...interface{}) (*sql.Row, error) {
	return m.db.QueryRow(query, args...), nil
}

func (m *MSSQL) Exec(query string, args ...interface{}) (sql.Result, error) {
	return m.db.Exec(query, args...)
}

func (m *MSSQL) Close() error {
	return m.db.Close()
}
